//
//  C_5ViewController.m
//  RACExamale
//
//  Created by cym_bj on 2017/12/1.
//  Copyright © 2017年 com.cym. All rights reserved.
//

#import "C_5ViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>

@interface C_5ViewController ()

@end

@implementation C_5ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title=@"计时器";
    
    //GCG计时器
    [self GCDTimer];
    
    //RAC计时器
    [self RACTimer];
    
    
}

#pragma mark- GCD计时器
-(void)GCDTimer
{
    
    dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));

    //设置间隔:
    // DISPATCH_TIME_NOW 现在开始   1.0 * NSEC_PER_SEC 参数为间隔为1秒
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0);
    dispatch_source_set_event_handler(timer, ^{

        NSLog(@"%@",timer);

    });
    dispatch_resume(timer);
    
   
    
    
}

#pragma mark -RAC计时器
-(void)RACTimer
{
    
    //[RACScheduler scheduler]  子线程
    // [RACScheduler mainThreadScheduler] 主线程
    
    [[RACSignal interval:1.0 onScheduler:[RACScheduler scheduler] ] subscribeNext:^(NSDate * _Nullable x) {
        
        NSLog(@"RAC---%@",x);
    }];
    
    
}

@end
